package com.wangcang.widgetlibrary.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;

import com.wangcang.widgetlibrary.R;
import com.wangcang.widgetlibrary.tools.ToastUtils;

public class MediaActivity extends AppCompatActivity implements View.OnClickListener {
    private Button mClipImage;
    private Button mUploadImage;
    private Button mSelectImage;
    private Button mAttachVideo;

    private static final int REQUEST_MEDIA_SELECT_IMAGE = 1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_media);

        mClipImage = (Button) findViewById(R.id.clip_image);
        mUploadImage = (Button) findViewById(R.id.upload_image);
        mSelectImage = (Button) findViewById(R.id.select_image);
        mAttachVideo = (Button) findViewById(R.id.attach_video);

        mClipImage.setOnClickListener(this);
        mUploadImage.setOnClickListener(this);
        mSelectImage.setOnClickListener(this);
        mAttachVideo.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        Intent intent;

        switch (v.getId()) {
            case R.id.clip_image:
                intent = new Intent(this, ClipImageActivity.class);
                startActivity(intent);
                break;
            case R.id.upload_image:
                intent = new Intent(this, UploadConfirmActivity.class);
                startActivity(intent);
                break;
            case R.id.select_image:
                intent = new Intent(this, SelectImageActivity.class);
                startActivityForResult(intent, REQUEST_MEDIA_SELECT_IMAGE);
                break;
            case R.id.attach_video:
                intent = new Intent(this, AttachVideoActivity.class);
                startActivity(intent);
                break;
            default:
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode == RESULT_OK) {
            switch (requestCode) {
                case REQUEST_MEDIA_SELECT_IMAGE:
                    if (data != null) {
                        String path = data.getStringExtra(SelectImageActivity.SELECT_IMAGE_PATH);
                        ToastUtils.showToast(path);
                    }
                    break;
                default:
                    break;
            }
        }
    }
}
